<?php


namespace api\web\controller;


use api\web\model\newsModel;
use cmf\controller\RestBaseController;

class newsController extends RestBaseController
{
    public function index(){
        $name = input('name');
        $where = [];
        if ($name){
            $where[] = ['title|authot' ,'like','%'.$name.'%'];
        }
        $pagerows = input('pagerows/d');
        $pagesize = input('pagesize');
        $data = newsModel::order('list_order','DESC')
            ->field('id,title,image,create_time,abstract')
            ->where($where)->page($pagerows,$pagesize)
            ->select();

        $this->success('中餐新闻',$data);
    }

    public function getNewsInform(){
        $id = input('id/d');
        if (empty($id)){
            $this->error('参数错误');
        }else{
            $list = newsModel::withoutField('delete_time,list_order')->find($id);
            $news = newsModel::find($id);
            if (empty($news)){
                $this->error('新闻不存在');
            }
            $content1= cmf_replace_content_file_url($news['content'],true);
            //移除html标签
            $news['content'] = strip_tags($content1) ;
            $this->success('新闻查询成功',$news);
        }
    }
}